1 program problem11203 (input, output);
\r
6 Function StrToInt(Const S: String): Integer;
\r
14 function allCharsEqual(s : string; c : char) : boolean;
\r
15 //Returns true if all chars from s equal c
\r
20 for i := 1 to length(s) do
\r
25 function extract(s : string; var x : string; var y: string; var z : string) : boolean;
\r
26 //returns true if it can extract x, y and z with the correct format, false otherwise.
\r
34 while ((s[i] <> 'M') and (i <= length(s))) do
\r
40 if (x = '') or (not allCharsEqual(x, '?')) then
\r
47 //delete from S from the beggining until the last character of x
\r
48 s := copy(s, i, length(s));
\r
49 if (s[1] <> 'M') then //if next char is not an M
\r
55 s := copy(s, 2, length(s)); //delete the M
\r
59 while ((s[i] <> 'E') and (i <= length(s))) do
\r
65 if (y = '') or (not allCharsEqual(y, '?')) then
\r
71 //delete from S from the beggining until the last character of y
\r
72 s := copy(s, i, length(s));
\r
79 z := copy(s, 2, length(s)); //delete the E
\r
80 if (z = '') or (not allCharsEqual(z, '?')) then
\r
87 function isTheorem(s : string) : boolean;
\r
93 if extract(s, x, y, z) then
\r
94 result := (x + y = z);
\r
100 i, principalLoop : integer;
\r
102 correctChars : Set of char;
\r
107 //reset(input, 'input.txt');
\r
108 //reset(output, 'out.txt');
\r
109 correctChars := ['M', 'E', '?'];
\r
111 howMany := strToInt(line);
\r
113 for principalLoop := 1 to howMany do
\r
117 for i := 1 to length(line) do
\r
118 if not (line[i] in correctChars) then
\r
121 writeLn('no-theorem')
\r
124 if isTheorem(line) then
\r
127 writeLn('no-theorem');
\r